package com.tedu.ds.contract.service.impl;

import com.tedu.ds.contract.mapper.ContractMapper;
import com.tedu.ds.contract.pojo.dto.ContractParam;
import com.tedu.ds.contract.pojo.dto.ContractQuery;
import com.tedu.ds.contract.pojo.entity.Contract;
import com.tedu.ds.contract.pojo.vo.ContractVO;
import com.tedu.ds.contract.service.ContractService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ContractServiceImpl implements ContractService {
    @Autowired
    private ContractMapper contractMapper;
    @Override
    public List<ContractVO> select(ContractQuery contractQuery) {
        return contractMapper.select(contractQuery);
    }

    @Override
    public void save(ContractParam contractParam) {
        Contract contract=new Contract();
        BeanUtils.copyProperties(contractParam,contract);
        if(contract.getId()==null){
            contractMapper.insert(contract);
        }else {
            contractMapper.update(contract);
        }
    }

    @Override
    public void delete(ContractParam contractParam) {
        contractMapper.delete(contractParam);
    }
}
